package org.example.day14.dao;

import org.example.day14.domain.User;
import org.example.day14.util.JDBCUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public class UserDao {
    private JdbcTemplate template=new JdbcTemplate(JDBCUtils.getDateSource());

    public User login(User loginUser){
        try {
            String sql="select * from user where name=? and password=?";
            User user = template.queryForObject(sql,
                    new BeanPropertyRowMapper<User>(User.class),
                    loginUser.getUsername(), loginUser.getPassword());
            return user;
        } catch (DataAccessException e) {
             e.printStackTrace();
             return null;
        }
    }
}
